package cn.com.xyc.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.xyc.dao.UserMapper;
import cn.com.xyc.pojo.User;
import cn.com.xyc.pojo.UserExample;
import cn.com.xyc.service.SystemService;

@Service
public class SystemServiceImpl implements SystemService {
	@Autowired
	private UserMapper userMapper;

	public int saveRegisterInfo(User user) {
		user.setCreateDate(new Date());
		user.setStatus(0);
		return userMapper.insertSelective(user);
	}

	public boolean checkUsername(String username) {
		UserExample example = new UserExample();
		example.createCriteria().andUsernameEqualTo(username);
		List<User> list = userMapper.selectByExample(example);
		if (list != null && list.size() > 0) {
			return false;
		} else {
			return true;
		}
	}

	public boolean checkUserActiveCode(String code) {
		UserExample example = new UserExample();
		example.createCriteria().andActivationEqualTo(code);
		List<User> list = userMapper.selectByExample(example);
		if (list != null && list.size() > 0) {
			return true;
		} else {
			return false;
		}
	}

}
